package com.twu.biblioteca;

import com.twu.biblioteca.Entity.User;
import com.twu.biblioteca.Model.BookList;
import com.twu.biblioteca.Model.MovieList;
import com.twu.biblioteca.Model.UserList;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class BibliotecaApp {

    public static void main(String[] args) {
        WelcomeMessage.showMessage();
        List<Service> services = getServices();
        MainMenu mainMenu = new MainMenu(services);
        while (true) {
            mainMenu.showMenu();
            String input = getSelection();
            boolean validServe = mainMenu.showSpecificMenu(input);
            if (validServe) services.get(Integer.valueOf(input) - 1).doService();
        }
    }

    public static String getSelection() {
        BufferedReader selection = new BufferedReader(new InputStreamReader(System.in));
        try {
            return selection.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "Select Error!";
    }

    private static List<Service> getServices() {
        List<Service> services = new ArrayList<Service>();
        BookList bookList = new BookList();
        MovieList movieList = new MovieList();
        UserList userList = new UserList();
        services.add(new BookViewService(bookList));
        services.add(new BookCheckOutService(bookList,userList));
        services.add(new BookReturnService(bookList));
        services.add(new MovieViewService(movieList));
        services.add(new MovieCheckOutService(movieList,userList));
        services.add(new UserAccountViewService(userList));
        return services;
    }
}



